import {
	objDeepCopy
} from "@/assets/js/common.js";
let Controller = {
	methods: {
		init() {
			this.getlist(this, 1);
		},
		handleSizeChange(val) {

		},
		handleCurrentChange(val) {

		},

		//获取列表数据
		getlist(that, level, code, theAttributeName) {
			var apiTest = this.apiTest;
			var url;
			// level == 1 ? url = '/api/saleGoodsAttributeClassify/list': url = '/api/saleGoodsAttribute/list';
			level == 1 ? url = apiTest + '/sale/saleGoodsAttributeClassify/list' : url = apiTest +
				'/sale/saleGoodsAttribute/list';
			this.$ajax({
				method: 'post',
				url: url,
				data: {
					condition: {
						attributeCode: code
					}
				}
			}).then((res) => {
				console.log(res);
				that.Model.tableData = [];
				var data = res.data;

				if (data.status == 200) {
					var obj = {};
					// that.paginationFunction(that,data.result);
					var result = data.result.result;
					for (var i = 0; i < result.length; i++) {
						obj = objDeepCopy(result[i]);
						if (level == 2) {
							obj.theAttributeName = theAttributeName;
						}
						//
						that.Model.tableData.push(obj);
					}
					if (level == 1) {
						that.Model.mediumTableData = objDeepCopy(that.Model.tableData);
					} else if (level == 2) {
						that.Model.smallTableData = objDeepCopy(that.Model.tableData);
					}
				} else {

				}
			});
		},
		//点击row查看
		handleClickItem(row) {
			this.Model.tableHeaderData = objDeepCopy(this.Model.smallTableHeader);
			this.Model.tableData = objDeepCopy(this.Model.smallTableData);
			this.Model.tableMsg = objDeepCopy(this.Model.smallTableMsg);
			this.getlist(this, 2, row.attributeCode, row.theAttributeName);

		},
		//返回上一页
		toMedium(type) {
			this.Model.tableMsg = objDeepCopy(this.Model.mediumTableMsg);
			this.Model.tableHeaderData = objDeepCopy(this.Model.mediumTableHeader);
			this.Model.tableData = objDeepCopy(this.Model.mediumTableData);
		}
	}
}
export default Controller;
